import { _decorator, Component, Node } from 'cc';
import { eventTarget, GameEventData } from '../Manager/SS_GameEventManager';
const { ccclass, property } = _decorator;

@ccclass('WaitingPanel')
export default class WaitingPanel extends Component {
    public static Instance: WaitingPanel;

    @property(Node)
    public loading: Node | null = null;

    //倒计时
    countDown: number = 5;

    onLoad() {
        WaitingPanel.Instance = this;
    }

    protected update(dt: number): void {
        if (this.loading) {
            this.loading.angle += -200 * dt;
        }
    }

    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();

        this.scheduleOnce(() => {
            this.ShowOff();
        }, this.countDown);
    }

    ShowOff() {
        this.node.active = false;
        this.RemoveListener();
    }

    async Refresh() {

    }

    AddListener() {
        eventTarget.on(GameEventData.广告结束, this.On_广告结束, this);
    }

    RemoveListener() {
        eventTarget.off(GameEventData.广告结束, this.On_广告结束, this);
    }

    On_广告结束() {
        this.ShowOff();
    }
}